﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.ComponentModel;
using ComApp.Model;
using ComApp;

namespace AndroidApp
{
    public class AppUnityInstance : IAppUnity
    {
        public User CurrentUser
        {
            get
            {
                return ThisApp.Instance.AppDeploy.CurrentUser;
            }
        }

        //InvokeInProxy -> InvokeOutProxy -> InvokeProxy -> WebSocketPool -> WebSocketClient
        //WebSocketPool -> WebSocketHeart -> WebSocketClient
        public AppUnityInstance()
        {
            FileLog.Instance.Log("AppUnityInstance.AppUnityInstance()");
            this.LogService = FileLog.Instance;
            var serverDeployXmlFile = System.IO.Path.Combine(AppPath.Instance.AppDataPath, "ServerDeploy.xml");
            if (System.IO.File.Exists(serverDeployXmlFile))
                this.ServerDeploy = new ServerDeployXml(serverDeployXmlFile);
            else
                this.ServerDeploy = new ServerDeploy();

            this.EntityReflectService = new EntityReflectService();
        }

        public void Start()
        {
            FileLog.Instance.Log("AppUnityInstance.Start()");
        }

        public void Close()
        {
            ThisApp.Instance.ViewManager.Close();
        }

        public ILogService LogService { get; private set; }
        public IServerDeploy ServerDeploy { get; private set; }
        public EntityReflectService EntityReflectService { get; private set; }
        

        public void RunOnUiThread(Action action)
        {
            ThisApp.Instance.ViewManager.FirstView.RunOnUiThread(action);
        }


    }
}
